{% extends 'master.html' %}

{% block All %}
		<div id="wrapper">
        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">主机管理</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
														<span style="font-size:16px;">主机信息</span>
														<a ><span id="updateAll" class="nav navbar-nav navbar-right " style="position: absolute;right: 72px;">一键更新</span></a>
                        </div>

                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
															  <thead>
																		<tr>
																				<th>序号</th>
																				<th>服务器名称</th>
																				<th>厂商</th>
																				<th>操作系统</th>
																				<th>CPU信息</th>
																				<th>内存总数(/M)</th>
																				<!--<th>状态</th>-->
																				<!--<th>录入时间</th>-->
																				<th>修正时间</th>
																				<th>操作</th>
																		</tr>
																</thead>
																<tbody id="dataTables-body">
																		{% for row in hardwares %}
																				<tr>
																						<td>{{ forloop.counter }}</td>
																						<td name="minion_db_id" value="{{ row.minion_id }}">{{ row.minion_id }}</td>
																						<td>{{ row.manufacturer }}</td>
																						<td>{{ row.osfullname }}</td>
																						<td>{{ row.cpu_model }}</td>
																						<td>{{ row.mem_total }}</td>
																						<!--if ({{ row.status }} == 1){-->
																							<!--<td>在线</td>-->
																						<!--} else if ({{ row.status }} == 2){-->
																							<!--<td>暂停</td>-->
																						<!--} else {-->
																							<!--<td>报废</td>-->
																						<!--}-->
																					<!--<td>{{ row.create_time }}</td>-->
																					<td>{{ row.end_time }}</td>
																					<td>
																						<a href="detailed-{{ row.id }}"><button id="detailed-{{ row.id }}" type="button" class="btn btn-primary" style="float:left;margin-left:5px">详细</button></a>
																						<span></span>
																						<button onclick="updateSerID('{{ row.minion_id }}')" type="button" class="btn btn-primary" id="{{ row.minion_id }}" style="float:left;margin-left:5px">更新</button>
																						<span></span>
																						<form id="{{ row.id }}" method="post" action="/backend/monitor" style="float:left;margin-left:5px">
																								{% csrf_token %}
																								<input name="minion_db_id" value="{{ row.minion_id }}" style="display: none" />
																								<button type="submit" class="btn btn-primary" >监控</button>
																						</form>
																					</td>
																				</tr>

																		{% endfor %}
																</tbody>
                            </table>
                            <!-- /.table-responsive -->

                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
{% endblock %}

{% block username %}{{ username }}{% endblock %}

{% block adminscript %}
<script>
//	表格相关的
		$(document).ready(function() {
				$('#dataTables-example').DataTable({
						responsive: true
				});
		});
</script>

<script>
	$('#updateAll').click(function(){
		$('#updateAll').text('正在执行更新....')
		$.ajax({
			url:'/api/cmdbcollect',
			type:'GET',
			data:{'serid':0,csrfmiddlewaretoken: '{{ csrf_token }}' },
			success:function(result){
			  var obj = JSON.parse(result);
				if(obj.status){
					alert(obj.message);
					window.location.reload();
				}else{
					alert(obj.message);
					window.location.reload();
				}
				$('#updateAll').text('一键更新')
			}
		})
	})
</script>

<script>
	function updateSerID(serid){
		$('#'+serid).removeAttr('onclick');
		$('#'+serid).text('更新中')
		$.ajax({
			url:'/api/cmdbcollect',
			type:'GET',
			data:{'serid':serid,csrfmiddlewaretoken: '{{ csrf_token }}' },
			success:function(result){
			  var obj = JSON.parse(result);
				if(obj.status){
					alert(obj.message);
					window.location.reload();
				}else{
					alert(obj.message);
					window.location.reload();
				}

			}
		})

	}

</script>

<script>
	function postMintior() {
		
  }
	
</script>


<!--<script language="javascript" type="text/javascript">-->
	<!--window.onload = function(){-->
			<!--var oTable = document.getElementById("dataTables-body");-->
			<!--for(var i=0;i<oTable.rows.length;i++){-->
					<!--oTable.rows[i].cells[0].innerHTML = (i+1);-->
					<!--if(i%2==0)    //偶数行-->
							<!--oTable.rows[i].className = "ys01";-->
			<!--}-->
	<!--}-->
<!--</script>-->
{% endblock %}